# coding: utf-8
from django.shortcuts import render
from django.shortcuts import get_object_or_404
from django.http import HttpResponseRedirect, HttpResponse, JsonResponse
from common.overwrites import z_render_to_response
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required

from django.conf import settings
from common.models.user import User, UserProfile
from common.models.position import JPositionCounty, JPositionTown, JPositionVillage
from common.models.post import Post


@login_required
@csrf_exempt
def my_hamlet(request):
    user = request.user
    xqs = UserProfile.objects.filter(village=user.userprofile.village)  # 乡亲们
    posts = Post.objects.filter(user__userprofile__village=user.userprofile.village)
    return z_render_to_response('my_hamlet.html', {'user': user,
                                                 'user_profile': user.userprofile,
                                                 'xqs': xqs,
                                                 'posts': posts})
